<?php

namespace App\Http\Controllers\api\doctor;

use App\Http\Controllers\Controller;
use App\Logic\doctor\DoctorLogic;
use App\Models\Doctor;
use App\Models\DoctorType;
use App\Server\ApiService;
use App\Server\EsService;
use App\Server\QiniuService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;

class DoctorController extends Controller
{
    /**
     * Name: 搜索医生
     * User: 王梓墨
     * Date: 2023/6/19
     * Time:10:03
     */
    public function searchDoctor(Request $request)
    {
        $data = $request->all();
        return DoctorLogic::searchDoctor($data);
    }

    public function createDoctor(Request $request)
    {
        $data=$request->except('_token');
        $file=$request->file('doctor_img');

        $data['doctor_img']=Storage::disk('public')->put('shixunhealthcare', $file);
        $data['doctor_img']=QiniuService::qiniu("storage/".$data['doctor_img']);
//        dd($data);
        try {
            $res=Doctor::create($data);
            $result = EsService::getInstance()->esCreate($res);
            if($result) {
                return ApiService::success('添加医师成功',$result);
            }
        } catch (\Exception $e) {
            Log::info($e->getMessage());
        }
    }
}
